package com.woniuxy.shirocore;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.env.BasicIniEnvironment;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;

public class LoginAuthBasicDemo {
    public static void main(String[] args) {
        //读取配置文件
        BasicIniEnvironment basicIniEnvironment = new BasicIniEnvironment("classpath:ini/shiro-auth.ini");
        //创建中央大脑
        SecurityManager securityManager = basicIniEnvironment.getSecurityManager();
        //使用工具类,王工具类中注入中央大脑
        SecurityUtils.setSecurityManager(securityManager);
        //创建subject
        Subject subject = SecurityUtils.getSubject();
        //模拟前端传过来的数据，通过login方法交给中央大脑校验是否正确
        subject.login(new UsernamePasswordToken("xiaozhou","654321"));
        //登陆成功
        System.out.println(subject.getPrincipal()+"登陆成功"+subject.isAuthenticated());
    }
}
